mini.parse();
var projectName = $("#projectName").val();
var form = new mini.Form("form1");
var orgId = '';
var contractNo = '';//合同号,用于加载该合同所包含的设备

function SaveData() {
	form.validate();
	if (form.isValid() == false)
		return;
	var json = GetData();
	CloseWindow(json);
}

////////////////////
//标准方法接口定义
function CheckEventSubTable(data) {
//跨页面传递的数据对象，克隆后才可以安全使用
	data = mini.clone(data);
	if (data.action == "edit") {
		SetData(data);
	} else if (data.action == "new") {
	}else if(data.action =="look"){
		SetData(data);
	}
}

function GetData(){
	var o = form.getData();
	return o;
}
function SetData(data){
	
}
function CloseWindow(action) {
	console.log(action);
	if (action == "close" && form.isChanged()) {
		if (confirm("数据被修改了，是否先保存？")) {
			return false;
		}
	}
	if (window.CloseOwnerWindow)
		return window.CloseOwnerWindow(action);
	else
		window.close();
}
function onOkSubTable(e) {
	SaveData();
}
function onCancelSubTable(e) {
	CloseWindow("cancel");
}

function labelModel() {
	var fields = form.getFields();
	for ( var i = 0, l = fields.length; i < l; i++) {
		var c = fields[i];
		if (c.setReadOnly)
			c.setReadOnly(true); //只读
		if (c.setIsValid)
			c.setIsValid(true); //去除错误提示
		if (c.addCls)
			c.addCls("asLabel"); //增加asLabel外观
	}
}
function inputModel() {
	var fields = form.getFields();
	for ( var i = 0, l = fields.length; i < l; i++) {
		var c = fields[i];
		if (c.setReadOnly)
			c.setReadOnly(false);
		if (c.removeCls)
			c.removeCls("asLabel");
	}
	mini.repaint(document.body);
}
function readOnlyForm(){
	$("#button_okSubTable").hide();
	$("#button_onSubTable").hide();
	form.setEnabled(false);
}
/////////////////////////////////////////////////////////////////////
/**设备列表页面**/
function onEquipmentEdit(){
	mini.open({
		url:projectName+'/TableDefineAdmin/equipmentselectPage',
		title:'设备列表',width:800,height:500,
		onload:function(){
			orgId = mini.get("ORG_ID").getValue();
			contractNo = mini.get("CONTRACT_NO").getValue();
			var iframe = this.getIFrameEl();
			var data = {orgId: orgId,contractNo: contractNo};
			iframe.contentWindow.CheckEventEquipment(data);
		},
		ondestroy:function ( action ){
			if(typeof(action)=="object"  && action.status==1){
				var data =action.rows;
				if(data.length>1){
					mini.alert("只能选中一条");
				}else{
					mini.get("EQ_ID").setValue(data[0].equipmentId);
					mini.get("EQ_ID").setText(data[0].equipmentName);
					mini.get("EQ_NAME").setValue(data[0].equipmentName);
					mini.get("EQ_CODE").setValue(data[0].equipmentCode);
					mini.get("EQ_TYPE_ID").setValue(data[0].equipmentType);
					mini.get("EQ_TYPE_ID").setText(data[0].equipmentTypeName);
					mini.get("EQ_TYPE_NAME").setValue(data[0].equipmentTypeName);
					mini.get("SUPPLIER_ID").setValue(data[0].supplierId);
					mini.get("SUPPLIER_NAME").setValue(data[0].supplierName);					
				}
			}
		}
		
	});
}

/**设备类型改变事件*/
function onEqTypeChanged(e){
	var eq_type_id = this;
	mini.get("EQ_ID").setValue("");
	mini.get("EQ_ID").setText("");
	mini.get("EQ_NAME").setValue("");
	mini.get("EQ_TYPE_NAME").setValue(eq_type_id.getText());
	mini.get("EQ_CODE").setValue("");
	mini.get("SUPPLIER_ID").setValue("");
	mini.get("EQ_CODE").setValue("");
}

